import http from "../index";

// 分页获取运单
export const getWaybills = ({
    ascended = null,
    current = null,
    size = null,
    sortFieldName = null,
    carrier = null,
    carSid = null,
    lineSid = null,
    status = null,
    code = null,
    wayBillState = null,
}) => {
    return http.get("waybill", {
        ascended,
        current,
        size,
        sortFieldName,
        carrier,
        carSid,
        lineSid,
        status,
        code,
        wayBillState,
    });
};

// 分配司机发车
export const assignDriverDeparture = ({ carSid, driversSid }) => {
    return http.post("waybill/assign-driver-departure", { carSid, driversSid });
};

// 获取未发车车辆下的运单
export const getWaybillsByUndeliveredCar = ({
    carSid,
    ascended = null,
    current = null,
    size = null,
    sortFieldName = null,
}) => {
    return http.get("waybill/get-waybill-by-car-id", {
        carSid,
        ascended,
        current,
        size,
        sortFieldName,
    });
};

// 分页获取相同线路所有未发车的运单
export const getUndeliveredWaybillsByLine = ({
    lineSid,
    carSid,
    ascended = null,
    current = null,
    size = null,
    sortFieldName = null,
    carrier = null,
    status = null,
    wayBillState = null,
    code = null,
}) => {
    return http.get("waybill/get-all-waybill", {
        lineSid,
        carSid,
        ascended,
        current,
        size,
        sortFieldName,
        carrier,
        status,
        wayBillState,
        code,
    });
};

// 分页获取订单下已发车的运单
export const getDeliveredWaybillsByOrder = ({
    sid,
    ascended = null,
    current = null,
    size = null,
    sortFieldName = null,
    carrier = null,
    wayBillCode = null,
    wayBillState = null,
}) => {
    return http.get("waybill/query-waybill-by-order-sid", {
        sid,
        ascended,
        current,
        size,
        sortFieldName,
        carrier,
        wayBillCode,
        wayBillState,
    });
};

// 分页获取可选择的线路
export const getWaybillLines = ({
    ascended = null,
    current = null,
    size = null,
    sortFieldName = null,
    lineName = null,
    outletsSid = null,
    status = null,
}) => {
    return http.get("waybill/get-line-by-waybill", {
        ascended,
        current,
        size,
        sortFieldName,
        lineName,
        outletsSid,
        status,
    });
};

// 分页获取所有待发车车次信息
export const getWaybillCars = ({
    ascended = null,
    current = null,
    size = null,
    sortFieldName = null,
    carHead = null,
    carNumber = null,
    carState = null,
    status = null,
}) => {
    return http.get("waybill/get-waybill-by-state", {
        ascended,
        current,
        size,
        sortFieldName,
        carHead,
        carNumber,
        carState,
        status,
    });
};

// 获取某条线路下可装车的车辆信息
export const getCarsByLine = ({
    lineSid,
    ascended = null,
    current = null,
    size = null,
    sortFieldName = null,
}) => {
    return http.get("waybill/car-by-line", {
        lineSid,
        ascended,
        current,
        size,
        sortFieldName,
    });
};

// 开始装车
export const entrucking = ({
    carSid,
    waybillSid,
    toolCode,
    note = null,
    status = null,
    code = null,
}) => {
    return http.post("waybill/loading", {
        carSid,
        waybillSid,
        toolCode,
        note,
        status,
        code,
    });
};

// 分页获取所有可分配的司机
export const getWaybillDrivers = ({
    ascended = null,
    current = null,
    size = null,
    sortFieldName = null,
    phone = null,
    nickName = null,
}) => {
    return http.get("waybill/page-driver", {
        ascended,
        current,
        size,
        sortFieldName,
        phone,
        nickName,
    });
};

// 根据订单sid分配运单
export const distributionWaybills = ({ sid }) => {
    return http.get("waybill/" + sid + "/split-waybill");
};

// 获取订单的运单
export const getOrderWaybills = ({ sid }) => {
    return http.get("waybill/" + sid + "/all-waybill");
};

// 删除订单的运单
export const delOrderWaybill = ({ sidList }) => {
    return http.put("waybill/delete", { sidList });
};

// 确认到达终点
export const confirmArrive = ({ sid }) => {
    return http.put("waybill/" + sid + "/system-arrive-at-destination");
};
